package com.ruoyi.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.system.domain.ACheckaInNew;
import com.ruoyi.system.domain.BigData;
import com.ruoyi.system.mapper.BigDataMapper;
import com.ruoyi.system.service.IACheckaInService;
import com.ruoyi.system.service.IBigDataServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class BigDataServerImpl implements IBigDataServer {

    @Autowired
    public RedisCache redisCache;

    @Autowired
    private IACheckaInService iaCheckaInService;

    @Autowired
    private BigDataMapper bigDataMapper;


    @Override
    public BigData bigDataInit() {
        BigData bigData = bigDataMapper.countAll();
        //转租数据
        List<JSONObject> jsonObjects = iaCheckaInService.checkAInListByDate11(new ACheckaInNew());
        bigData.setSubletCount(jsonObjects == null ? 0 : jsonObjects.size());
        //报警数据
        List<Map<String,Object>> warnList = bigDataMapper.getWarningList();
        if (!warnList.isEmpty()) {
            bigData.setWarningList(JSON.toJSONString(warnList));
        }
        bigData.setWarningCount(bigDataMapper.getWarningCount());
        return bigData;
    }
}
